//
//  XYBaseTableViewController.swift
//  01-新浪微博
//
//  Created by 陈许亚 on 16/3/7.
//  Copyright © 2016年 cxy. All rights reserved.
//

import UIKit

class XYBaseTableViewController: UITableViewController,XYVisitorLoginViewDelegate {
    
    //用户登录指示
    var userLogin = XYUserAccount.sharedAccount.userLogin
    
    var visitorView: XYVisitorLoginView?
    
    override func loadView() {
        if userLogin {
            //
            super.loadView()
        }else {
            
            //用户没有登录，进入访客视图，
            visitorView = XYVisitorLoginView()
            //将view设置为访客视图
            view = visitorView
            
            //设置代理
            visitorView?.visitorLoginViewDelegate = self
            
            navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "userWillLogin")
            navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "userWillRegeist")
        }
        
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(true)
        loadView()
    }
    
    func userWillLogin(){
        //用户将要登录
        print("ss")
        /**
         1.先创建一个要modal出来的控制器，
         2.因为是有导航栏样式的，所以要创建出来的导航控制器的rootViewController设置成创建出来的这个控制器
         3.presentViewController
         */
        let oAuth = XYOAuthViewController()
        let nav = UINavigationController(rootViewController: oAuth)
        
        presentViewController(nav, animated: true, completion: nil)
        
    }
    
    func userWillRegeist(){
        //用户将要注册
        
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
}
